<?php
App::uses('AppModel', 'Model');
/**
 * Article Model
 *
 * @property Menuses $Menuses
 * @property Domain $Domain
 * @property Post $Post
 */
class Article extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Please write title',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'descriptions' => array(
				'notempty' => array(
						'rule' => array('notempty'),
						'message' => 'Please write descriptions',
						//'allowEmpty' => false,
						//'required' => false,
						//'last' => false, // Stop validation after this rule
						//'on' => 'create', // Limit validation to 'create' or 'update' operations
				),
		),
		'domain_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Menus' => array(
			'className' => 'Menus',
			'foreignKey' => 'menuses_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Submenu' => array(
			'className' => 'Submenu',
			'foreignKey' => 'submenu_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Domain' => array(
			'className' => 'Domain',
			'foreignKey' => 'domain_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
	public $hasAndBelongsToMany = array(
		'Post' => array(
			'className' => 'Post',
			'joinTable' => 'posts_articles',
			'foreignKey' => 'article_id',
			'associationForeignKey' => 'post_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => '',
			'dependent' => true
		),
		'Upload' => array(
			'className' => 'Upload',
			'joinTable' => 'articles_uploads',
			'foreignKey' => 'article_id',
			'associationForeignKey' => 'upload_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => '',
			'dependent' => true
		),
		'Rating' => array(
			'className' => 'Rating',
			'joinTable' => 'rating_articles',
			'foreignKey' => 'article_id',
			'associationForeignKey' => 'rating_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => 'Rating.rating_group_id',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => '',
			'dependent' => true
		),
		'Comment' => array(
			'className' => 'Comment',
			'joinTable' => 'articles_comments',
			'foreignKey' => 'article_id',
			'associationForeignKey' => 'comment_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => '',
			'dependent' => true
		)
	);

	public function afterSave( $options = array() ) {
		if(isset($this->data['Article']['domain_id'])){
			$this->Domain->id = $this->data['Article']['domain_id'];
			$this->Domain->saveField('cache',1);
		}
		return true;
	}
	
	
	
}


